package com.act.config;

import cn.dev33.satoken.exception.NotLoginException;
import com.act.utils.DataResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * springboot全巨额统一异常处理
 *
 * @author monxz
 *
 */
@ControllerAdvice
public class BaseControllerException {

    /**
     * 全局异常捕捉处理
     *
     * @param ex
     * @return
     */
    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public DataResult errorHandler(Exception ex) {
        ex.printStackTrace();
        if(ex instanceof NotLoginException){
            return DataResult.fail("登录状态异常");
        }
        return DataResult.fail(ex.getMessage());

    }
}

